package com.huizhonglm.diap.ui.wallet;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.R;
import com.huizhonglm.diap.api.model.wallet.BankCardInfo;

import java.util.List;

/**
 * 推荐关注用户列表适配器
 *
 * @author LiXiaolong
 * @version 1.0
 * @since 2014年8月11日下午4:25:25
 */
public class BankCardListAdapter extends BaseAdapter {
    private Context mContext;
    private List<BankCardInfo> mData;

    public BankCardListAdapter(Context con, List<BankCardInfo> data) {
        this.mContext = con;
        this.mData = data;
    }

    public void setData(List<BankCardInfo> data) {
        this.mData = data;
    }

    @Override
    public int getCount() {
        return EmptyUtil.isEmpty(mData) ? 0 : mData.size();
    }

    @Override
    public BankCardInfo getItem(int position) {
        return EmptyUtil.isEmpty(mData) ? null : mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = View.inflate(mContext, R.layout.item_bank_cards, null);
            holder.bankName = (TextView) view.findViewById(R.id.bank_name_txt);
            holder.cardNo = (TextView) view.findViewById(R.id.card_no_txt);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        final BankCardInfo info = getItem(position);
        if (info != null) {
            holder.bankName.setText(info.getBankName());
            holder.cardNo.setText(info.getCardNo());
        }
        return view;
    }

    private class ViewHolder {
        private TextView bankName;
        private TextView cardNo;
    }

}
